﻿import javax.xml.soap.Text;
import java.io.*;

/**
 * Created by hepeng on 2017/6/21.
 */
public class Read {
    public Read() {
    }
    static Read read=new Read();

    /**
     * @param args
     */
    public static void main(String[] args) {
        String ss=read.getClass().getResource("/").getPath();
        String path=read.getClass().getResource("/").getPath();
        //java.io.File.separator  可平台分割
        readFileByLines( "/Users/hepeng/Downloads/123.sql");
    }
    /**
     * 以行为单位读取文件，常用于读面向行的格式化文件
     */
    public static void readFileByLines(String fileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        try {
            System.out.println("以行为单位读取文件内容，一次读一整行：");
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int i = 1;
            // 一次读入一行，直到读入null为文件结束
            String str = "" ;
            String a = "" ;
            while ((a=reader.readLine())!=null) {
//                System.out.println(i);
//                System.out.println("str:"+a) ;
                if(a.trim().length()==0){
                    continue;
                }
                str+=a ;
                // 显示行号
                if(i%2==0 && i!=0){


                    System.out.println(str.substring(0,str.indexOf("LOADER_ID")+21)+" ;");
                    str="" ;
                }

               i++ ;
            }
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                 }
            }
        }
    }

}
